package demo.controller;

import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Page;
import demo.domain.CourseSelect;


import java.util.List;


@Path(value = "/teacher")
@Clear
public class TeacherController extends Controller {
    public void index() {
//            List<Student> all = new Student().findAll();
//            Student student= (Student) all;

        int page=1;
        int size=7;
        if (get("page")!=null&&get("size")!=null){
            page= Integer.parseInt(get("page"));
            size= Integer.parseInt(get("size"));
        }
        set("page",page);
        set("size",size);
        Page<CourseSelect> fromCourseSelect = CourseSelect.dao.paginate(page, size, "select * ", "from course_select");
        List<CourseSelect> courseList = fromCourseSelect.getList();
        int totalPage = fromCourseSelect.getTotalPage();
        set("totalPage",totalPage);
        set("courseList", courseList);
        set("total",fromCourseSelect.getTotalRow());
        render("index.html");
    }

    @Clear
    public void deleteCourse(){
      String courseId=  get("courseId");
      CourseSelect.dao.deleteById(courseId);
     String page= get("page");
        String size= get("size");
        set("page",page);
        set("size",size);
        System.out.println("page+size"+page+" "+size);
        redirect("teacher?page="+page+"&size="+size);
    }
}